/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.taxigang.server;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.google.appengine.api.datastore.Key;
import com.taxigang.shared.AwardInfo;

/**
 *
 * @author hall
 */
@Entity
@Table(name = "AWARD")
@NamedQueries({	@NamedQuery(	name = "Award.findAll", 		query = "SELECT a FROM Award a ")}) 
public class Award implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "AWARDKEY", nullable = false)
    private Key key;
    @Column(name = AWARDTEXT, nullable = true)
    private String awardText;    
    @Column(name = DATE, nullable = false)
    private Date date;
    @Column(name = AUTHORNAME, nullable = true)
    private String authorName;
    @Column(name = POINTS, nullable = true)
    private Integer points;

    public static final  String DATE="DATE";
    public static final  String AWARDTEXT="AWARDTEXT";
    public static final  String AUTHOR="AUTHOR";
    public static final  String AUTHORNAME="AUTHORNAME";
    public static final  String POINTS="POINTS";
    
    
    @ManyToOne(fetch = FetchType.LAZY)
    private TaxiGang taxiGang;
    
    public Award(AwardInfo awardInfo) {
    	this.date = awardInfo.getDate();
    	this.awardText = awardInfo.getAwardText();
    	this.authorName= awardInfo.getAuthorName();
    	this.points= awardInfo.getPoints();

    }
    
    
	public long getId() {
		return key.getId();
	}

    public AwardInfo getInfo(){
    	AwardInfo info = new AwardInfo(awardText,date,authorName,points);
    	
    	return info;
    }

    public String getAuthorName() {
        return authorName;
    }
    
    public void setAuthorName(String name) {
        authorName = name;
    }
    
    /**
     * Get date
     * @return
     */
    public Date getDate() {
        return date;
    }
    
    public void setDate(Date d) {
        date = d;
    }
    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Award)) {
            return false;
        }
        Award other = (Award) object;
        if ((this.key == null && other.key != null) || (this.key != null && !this.key.equals(other.key))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "taxigangsystem.beans.TaxiGang[taxigangid=" + key.getId() + "]";
    }


	public Integer getPoints() {
		// TODO Auto-generated method stub
		return points;
	}

}
